import { BaseWindow } from "../../../component/window/BaseWindow";
import { ShopConfig } from "../../resource/ShopConfig";
import { ShopItemInfo } from "../../resource/info/ShopItemInfo";
import { ItemData } from "../../resource/info/ItemData";
import { ColorConfig } from "../../resource/ColorConfig";
import { ObjCreate } from "./ObjCreate";
import { Language } from "../../../../extend/language/Language";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { BaseItem } from "./BaseItem";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
import { GNumericStepper } from "../../../../com/mui/controls/GNumericStepper";
import { ResouceConst } from "../../../component/gconst/ResouceConst";
import { ImagesConst } from "../../resource/ImagesConst";
import { BuyAlert } from "../pet/BuyAlert";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { GButton } from "../../../../com/mui/controls/GButton";
import { TItem } from "../../../../Message/Db/Tables/TItem";
import { ColorInfo } from "../../resource/info/ColorInfo";
type int = number;
//class QuickBuyWindow
    
    export  class QuickBuyWindow extends BaseWindow
    {
        constructor()
        {
            super();
            this._ingot = new Object /* flash.display.Bitmap */();
            if (QuickBuyWindow._instance != null) 
            {
                throw new Error(" QuickBuyWindow 单例 ");
            }
            this.init();
            return;
        }

        public updateWindow(arg1: int, arg2: int, arg3: int=1, arg4: int=-1, arg5: Boolean=true, arg6: int=-1): Boolean
        {
            this.shopItemInfo = ShopConfig.instance.getItemByType(arg1, arg2, arg3, arg4, arg5, arg6);
            if (this.shopItemInfo) 
            {
                this.update(this.shopItemInfo);
                return true;
            }
            return false;
        }

        /* internal  */initData(arg1: ShopItemInfo): void
        {
            this.shopItemInfo = arg1;
            if (arg1) 
            {
                this._priceType = arg1.unit;
                if (arg1.itemInfo && arg1.itemInfo.item) 
                {
                    this.item = this.shopItemInfo.itemInfo.item;
                    this.itemData = new ItemData(this.item.code);
                    this.colorInfo = ColorConfig.instance.getItemColor(this.item.color);
                    if (this.colorInfo) 
                    {
                        this.colorName = this.colorInfo.color;
                    }
                }
            }
            return;
        }

        public init(): void
        {
            this.setSize(300, 195);
            this.titleHeight = 28;
            ObjCreate.createBg(20, 42, 260, 138, this);
            this.title = Language.getString(42900);
            this._tipText = ObjCreate.createTextField("", 11, 47, 170, 20, this, GlobalStyle.textFormat2);
            this._tipText.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._bg = GlobalClass.getBitmap("PropBg");
            this._bg.x = 35;
            this._bg.y = 65;
            this.addChild(this._bg);
            this._propItem = new BaseItem();
            this._propItem.isDragAble = false;
            this._propItem.setSize(60, 60);
            this._propItem.label = "";
            this._propItem.move(40, 70);
            this.addChild(this._propItem);
            this._nameText = new GTextFiled();
            this._nameText.x = 107;
            this._nameText.y = 67;
            this.addChild(this._nameText);
            ObjCreate.createTextField(Language.getString(42901), 107, 90, 100, 20, this);
            this._priceNumText = ObjCreate.createTextField("", 150, 90, 35, 20, this);
            this._priceNumText.autoSize = flash.text.TextFieldAutoSize.RIGHT;
            this._ingot = new Object /* flash.display.Bitmap */();
            this._ingot.x = 190;
            this._ingot.y = 90;
            this.addChild(this._ingot);
            ObjCreate.createTextField(Language.getString(42902), 107, 112, 100, 20, this);
            this._numericStepper = new GNumericStepper();
            this._numericStepper.drawNow();
            this._numericStepper.setSize(60, 22);
            this._numericStepper.move(155, 110);
            this._numericStepper.styleName = "NumericStepper";
            this._numericStepper.drawNow();
            this._numericStepper.textField.setStyle("upSkin", ResouceConst.getScaleBitmap(ImagesConst.WindowCenterB));
            this._numericStepper.textField.drawNow();
            this._numericStepper.maximum = 99;
            this._numericStepper.minimum = 1;
            this.addChild(this._numericStepper);
            this._okBtn = ObjCreate.createGButton(Language.getString(42903), 74, 151, 48, 27, this);
            this._okBtn.name = "SaleButton";
            this._okBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onOkBtnClickHandler);
            this._cancelBtn = ObjCreate.createGButton(Language.getString(42904), 170, 151, 48, 27, this);
            this._cancelBtn.name = "SaleButton";
            this._cancelBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onCancelBtnClickHandler);
            return;
        }

        /* internal  */onOkBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=this._numericStepper.value;
            if (this.shopItemInfo) 
            {
                this.shopItemInfo.buyNum = loc1;
                BuyAlert.showByShopItemInfo(this.shopItemInfo);
                this.hide();
            }
            return;
        }

        /* internal  */onCancelBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.hide();
            dispatchEvent(new DataEvent(EventName.QuickBuyCancel));
            return;
        }

        public /* override */ update(arg1: Object, ... rest): void
        {
            if (arg1 && arg1 is ShopItemInfo) 
            {
                this.initData(arg1 as ShopItemInfo);
            }
            this._priceImgName = GameDefConfig.instance.getEPrictUnitImg(this._priceType);
            if (this._priceImgName != "") 
            {
                this._ingot.bitmapData = GlobalClass.getBitmapData(this._priceImgName);
            }
            if (this.item) 
            {
                this._nameText.htmlText = HTMLUtil.addColor(this.item.name, this.colorName);
                this._tipText.text = Language.getStringByParam(42905, this.item.name);
                this._tipText.x = (this.width - this._tipText.width) / 2;
            }
            var loc1=this.shopItemInfo.tshopSell.offer == 0 ? this.shopItemInfo.tshopSell.price : this.shopItemInfo.tshopSell.offer;
            this._priceNumText.text = loc1.toString();
            this._numericStepper.value = 10;
            this._propItem.itemData = this.itemData;
            return;
        }

        public updateDefaultAmount(arg1: int): void
        {
            if (arg1 <= 1) 
            {
                this._numericStepper.value = 1;
            }
            else 
            {
                this._numericStepper.value = arg1;
            }
            return;
        }

        public static get instance(): QuickBuyWindow
        {
            if (QuickBuyWindow._instance == null) 
            {
                QuickBuyWindow._instance = new QuickBuyWindow();
            }
            return QuickBuyWindow._instance;
        }

        /* internal */ /* var */_tipText: Object /* flash.text.TextField */;

        /* internal */ /* var */_bg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_nameText: GTextFiled;

        /* internal */ /* var */_propItem: BaseItem;

        /* internal */ /* var */_priceText: GTextFiled;

        /* internal */ /* var */_amountText: GTextFiled;

        /* internal */ /* var */_priceNumText: Object /* flash.text.TextField */;

        /* internal */ /* var */_ingot: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_numericStepper: GNumericStepper;

        /* internal */ /* var */_okBtn: GButton;

        /* internal */ /* var */_cancelBtn: GButton;

        /* internal */ /* var */shopItemInfo: ShopItemInfo;

        /* internal */ /* var */itemData: ItemData;

        /* internal */ /* var */item: TItem;

        /* internal */ /* var */colorInfo: ColorInfo;

        /* internal */ /* var */colorName: string;

        /* internal */ /* var */_priceType: int;

        /* internal */ /* var */_priceImgName: string="Yuanbao";

        /* internal */ static /* var */_instance: QuickBuyWindow;
    }
